package com.study.demo_json.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.text.SimpleDateFormat;

/**
 * @ClassName: WebConfig
 * @Description:
 * @author: WS
 * @date 2020/12/10
 * @Version: 1.0
 **/
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Bean
    MappingJackson2HttpMessageConverter jackson2HttpMessageConverter(){
        MappingJackson2HttpMessageConverter converter=new MappingJackson2HttpMessageConverter();
        ObjectMapper objectmapper=new ObjectMapper();
        objectmapper.setDateFormat(new SimpleDateFormat("yyyy/MM/dd"));
        converter.setObjectMapper(objectmapper);
        return converter;
    }
//    @Bean
//    ObjectMapper objectMapper(){
//        ObjectMapper objectmapper=new ObjectMapper();
//        objectmapper.setDateFormat(new SimpleDateFormat("yyyy\\MM/dd"));
//        return objectmapper;
//    }
}
